<?php
/**
 * Created by Jasmine.
 * Date: 2016/8/1
 * description:
 * Address: 浙江宣逸网络科技有限公司
 */

namespace Admin\Controller;
use Admin\BaseController;
use Common\Model\CouponModel;
use Common\Model\SignLuckyModel;
use Think\Page;

class SignController extends BaseController{

    const FIELD_SEPARATOR   ="\t\t\t";
    const LINE_SEPARATOR    ="\n\n\n";

    //连续登录奖励界面
    public function continuousLoginBonus(){
        $luckyM = M('lucky_prize',null,DB_MAIN_CFG);
        $data = $luckyM->where('type='.SignLuckyModel::PRIZE_TYPE_SIGN_CONTINUE)->field('prizeRank,extra,id')->select();
        $this->smarty->assign('data',$data);
//        print_r($data);die;
        $this->smarty->display('Sign/continuousSign.html');
    }

    //保存；连续登录奖励设置
    public function saveContinuousLogin(){
        $param = I('get.param');
        if(!$param) {
            $this->ajaxReturn(array('status' => 0, 'msg' => '保存成功'));
        }

        $array = explode(';',$param);
        foreach($array as $v){
            $arr[] = explode(',',$v);
        }

        $luckyM = M('lucky_prize',null,DB_MAIN_CFG);
        foreach($arr as $key => $val ){
            if($val[1]=='' || $val[2] ==''){
                unset($arr[$key]);
            }else{
                if($val[0]=='0'){
                    //添加
                    $data[] = array(
                        'type'      => SignLuckyModel::PRIZE_TYPE_SIGN_CONTINUE,
                        'prizeRank' => $val[1],
                        'prizeType' => ELEMENT_TYPE_POINT,
                        'prizeName' => '连续登录奖励',
                        'hitRate'   => 1,
                        'prizeNum'  => -1,
                        'extra'     => $val[2]
                    );
                } else if($val[0] !='' && $val[0]!='0'){
                    //更新
                    $update = array('prizeRank'=>$val[1],'extra'=>$val[2]);
                    $luckyM->where("id={$val[0]}")->setField($update);
                }
            }
        }
        $luckyM->addAll($data);
        $this->ajaxReturn(array('status'=>0,'msg'=>'恭喜您，配置成功'));
    }

    //删除连续签到奖励设置
    public function delContinuousLogin(){
        $id=I('get.id',0,'intval');
        if(!$id){
            $this->ajaxReturn(array('status'=>1,'msg'=>'参数错误'));
        }
        $luckyM = M('lucky_prize',null,DB_MAIN_CFG);
        if($luckyM->where("id={$id}")->find()){
            $del = $luckyM->delete($id);
            if($del) $this->ajaxReturn(array('status'=>0,'msg'=>'删除成功'));
            else $this->ajaxReturn(array('status'=>1,'msg'=>'删除失败'));
        }else{
            $this->ajaxReturn(array('status'=>1,'msg'=>'该配置已删除，请刷新后重试'));
        }
    }

    //宝箱奖励界面
    public function signPrizeIndex(){
        $type = C('ELEMENT_TYPE');
        $this->smarty->assign('type',$type);
        $cardM = M("card_base_info",null,DB_MAIN_CFG);
        $cardInfo = $cardM->where("stock > 0")->field('id,title')->select();
        $cardID = array(); $cardTitle = array();
        foreach($cardInfo as $val){
            $cardID[] = $val['id'];
            $cardTitle[] = $val['title'];
        }
        $this->smarty->assign('cardID',$cardID);
        $this->smarty->assign('cardTitle',$cardTitle);

        $data = M('lucky_prize',null,DB_MAIN_CFG)
            ->field("lucky_prize.*,elect_card_base_info.title")
            ->join("left join elect_card_base_info on lucky_prize.extra = elect_card_base_info.id")
            ->where("type=".SignLuckyModel::PRIZE_TYPE_SIGN_LUCKY)
            ->order("lucky_prize.id ASC")
            ->select();
        $this->smarty->assign('obj',$data);

        $this->smarty->assign('num',5);//配置中奖项数量
        $this->smarty->display('Sign/setSignPrize.html');
    }

    //保存大转盘配置
    public function saveLuckyInfo(){
        $prizeId = I('get.prizeId');
        $prizeRank = I('get.prizeRank');
        $prizeName = I('get.prizeName');
        $hitRate = I('get.hitRate');
        $dayLimitTimes = I('get.dayLimit');
        $allLimitTimes = I('get.allLimit');
        $prizeNum = I('get.prizeNum');
        $prizePic = I('get.prizePic');
        $prizeType = I('get.prizeType');
        $extra = I('get.prizeSet');

        $type = I('get.type',SignLuckyModel::PRIZE_TYPE_SIGN_LUCKY,'int');
        //检查奖品名称是否填写完整
        foreach ($prizeName as $key => $val){
            if(!$val){
                $this->ajaxReturn(array('status' => 1, 'msg' => "请填写奖品名称", 'id' => $key));
            }
        }

//        判断中奖率是否为1
        if(array_sum($hitRate) != 1){
            $this->ajaxReturn(array('status' => 2, 'msg' => "中奖率总和不为1，请重新配置"));
        }
        //卡券数量核实
        foreach($prizeType as $k => $v){
            if($v == ELEMENT_TYPE_CARD){
                if(!$extra[$k] || $extra[$k] <= 0){
                    $this->ajaxReturn(array('status' => 6, 'msg' => "请选择奖品卡券" ,'id' => $k));
                } elseif($prizeNum[$k] > 0){
                    //可用数量
                    $availableNum = CouponModel::getAvailableCardNum($extra[$k]);
                    //已分配可用剩余数量
                     $assignedUsableNum = M('card_code',null,DB_MAIN_CFG)->where("objType=".OBJ_TYPE_LUCKY." and objID={$prizeId[$k]} and status =".CouponModel::CODE_STATUS_DEFAULT." and cardId={$extra[$k]}")->count();
                    //需要再分配的值
                    $needNum = $prizeNum[$k] - $assignedUsableNum;
                    if($needNum < 0){
                        $this->ajaxReturn(array('status' => 4, 'msg' => "该奖项已分配该卡券，剩余可用".$assignedUsableNum."张，请输入不小于该数值的值" ,'id' => $k));
                    } elseif($needNum > 0){
                        if($needNum > $availableNum){
                            $this->ajaxReturn(array('status' => 4, 'msg' => "卡券数量大于可用数量".$availableNum."，请重新设置" ,'id' => $k));
                        } else{
                            M('card_code',null,DB_MAIN_CFG)
                                ->where("cardId=$extra[$k] and status=".CouponModel::CODE_STATUS_DEFAULT." and objType=".OBJ_TYPE_ALL)
                                ->limit($needNum)
                                ->setField(array('objType'=>OBJ_TYPE_LUCKY,'objID'=>$prizeId[$k]));
                        }
                    }else{
                        //不分配
                    }
                } else{
                    $this->ajaxReturn(array('status' => 4, 'msg' => "请输入卡券奖品数量" ,'id' => $k));
                }
            } elseif($v == ELEMENT_TYPE_POINT){
                if($extra[$k]<=0 || !$extra[$k]){
                    $this->ajaxReturn(array('status' => 3, 'msg' => "请正确输入中奖积分" ,'id' => $k));
                }
            } elseif ($v == ELEMENT_TYPE_ECOUPONS){
                if($extra[$k] <=0 || !$extra[$k]){
                    $this->ajaxReturn(array('status' => 7, 'msg' => "请正确选择异业券" ,'id' => $k));
                }
            }
        }
        //检查奖品图片是否填写完整
        foreach ($prizePic as $key=>$val){
            if(!$val){
                $this->ajaxReturn(array('status' => 5,'msg' => "请选择奖品图片",'id' => $key));
            }
        }
        $data = array();
        foreach($prizeId as $key => $val){
            $data[$key]['prizeRank'] = $prizeRank[$key];
            $data[$key]['prizeName'] = $prizeName[$key];
            $data[$key]['prizeType'] = $prizeType[$key];
            $data[$key]['hitRate'] = $hitRate[$key];
            $data[$key]['dayLimitTimes'] = $dayLimitTimes[$key];
            $data[$key]['allLimitTimes'] = $allLimitTimes[$key];
            $data[$key]['prizeNum'] = $prizeNum[$key];
            $data[$key]['extra'] = $extra[$key];
            $data[$key]['type'] = $type;
            $data[$key]['prizePic'] = $prizePic[$key];
        }

        $luckyM = M('lucky_prize',null,DB_MAIN_CFG);
        $id = $luckyM->where("type={$type}")->getField('id',true);
        if($id && count($id) == count($data)){
            $i=0;
            foreach($prizeId as $v){
                $result = $luckyM->where("id={$v}")->save($data[$i]);
                $i++;
                if(false === $result && 0 === $result) {
                    $this->ajaxReturn(array('status' => '1', 'msg' => '第'.$i.'条更改失败'));
                }
            }
            $this->ajaxReturn(array('status' => '0','msg'=>'更改成功'));
        } else{
            $luckyM->addAll($data);
        }
        $this->ajaxReturn(array('status' => '0','msg'=>'保存成功'));
    }

    //日签到统计页面
    public function daySignCount(){
        $date = I('get.date');
        $nickname = I('get.nickname','');
        $bindPhone = I('get.bindPhone','');
        if(!$date){
            $date = date("Y-m-d");
        }
        $where = "1";
        $time = strtotime($date);
        $todayStart = mktime(0,0,0,date('m',$time),date('d',$time),date('Y',$time));
        $todayEnd = mktime(23,59,59,date('m',$time),date('d',$time),date('Y',$time));
        $where .= " and addTime between $todayStart and $todayEnd";

        if($bindPhone){
            $uid = M('u_user_base',null,DB_MAIN_CFG)->where("bindPhone='{$bindPhone}'")->getField("uid");
            $where .=" and uid = {$uid}";
        } else if($nickname){
            $uid = M('u_user_base',null,DB_MAIN_CFG)->where("nickname like '%{$nickname}%'")->getField("uid",true);
            $uidStr = implode(',',$uid);$where .= " and uid in ({$uidStr})";
        }

        $count = M('u_sign_log',null,DB_MAIN_CFG)->where($where)->count();
        $this->smarty->assign('totalDataCount',$count);

        $limit = I('get.limit',10,'int');
        $Page = new Page($count,$limit);
        fetchPage($this->smarty,$Page);

        $data = M('u_sign_log',null,DB_MAIN_CFG)
            ->where($where)
            ->order("addTime ASC")
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->select();

        if($data){
            $uidArr=array();
            foreach($data as $val){
                $uidArr[] = $val['uid'];
            }
            $uidStr = implode(',',$uidArr);
            $userInfo = M('u_user_base',null,DB_MAIN_CFG)->where("uid in ({$uidStr})")->field("uid,nickname,realName,bindPhone")->select();
            foreach($data as $key => $value){
                foreach($userInfo as $v){
                    if($value['uid'] == $v['uid']){
                        $data[$key]['nickname'] = $v['nickname'];
                        $data[$key]['realName'] = $v['realName'];
                        $data[$key]['bindPhone'] = $v['bindPhone'];
                        break;
                    }
                }
            }
        }

        $this->smarty->assign('data',$data);
        $this->smarty->assign('date',$date);
        $this->smarty->assign('bindPhone',$bindPhone);
        $this->smarty->assign('nickname',$nickname);
        $this->smarty->assign('signNum',$count);
        $this->smarty->assign('limit',$limit);
        $this->smarty->assign('title',"每日签到排行");
        $this->smarty->display("Sign/daySignCount.html");
    }

    //总签到统计页面
    public function allSignCount(){
        $nickname = I('get.nickname','');
        $bindPhone = I('get.bindPhone','');
        $where = '1';
        $u_baseM =  M('u_user_base',null,DB_MAIN_CFG);

        if($bindPhone){
            $uid = $u_baseM->where("bindPhone='{$bindPhone}'")->getField('uid');
            $where .= " and uid=$uid";
        } else if($nickname){
            $uid = $u_baseM->where("nickname like '%{$nickname}%'")->getField('uid',true);
            $uidStr = implode(',',$uid);$where .= " and uid in ({$uidStr})";
        }

        $count = M('u_sign_rank',null,DB_MAIN_CFG)->where($where)->count();
        $this->smarty->assign('totalDataCount',$count);

        $limit = I('get.limit',10,'int');
        $Page = new Page($count,$limit);
        fetchPage($this->smarty,$Page);

        $data = M('u_sign_rank',null,DB_MAIN_CFG)
            ->where($where)
            ->order("rank ASC")
            ->limit($Page->firstRow.','.$Page->listRows)
            ->select();

        if($data){
            $uidArr = array();
            foreach($data as $val){
                $uidArr[] = $val['uid'];
            }
            $uidArrStr = implode(',',$uidArr);
            $info = $u_baseM->where("uid in ({$uidArrStr})")->field("uid,lastLoginTime,nickname,realName,bindPhone")->select();
            foreach($data as $key=>$val){
                foreach($info as $v){
                    if($val['uid'] == $v['uid']){
                        $data[$key]['lastLoginTime'] = $v['lastLoginTime'];
                        $data[$key]['nickname'] = $v['nickname'];
                        $data[$key]['realName'] = $v['realName'];
                        $data[$key]['bindPhone'] = $v['bindPhone'];
                        break;
                    }
                }
            }
        }

        $this->smarty->assign('data',$data);
        $this->smarty->assign('bindPhone',$bindPhone);
        $this->smarty->assign('nickname',$nickname);
        $this->smarty->assign('limit',$limit);
        $this->smarty->assign('title',"总签到排行");
        $this->smarty->display("Sign/allSignCount.html");
    }
    //抽奖记录
    public function signLuckyRecord(){
        $startDate = I('get.startDate','');
        $endDate = I('get.endDate','');
        $prizeRank = I('get.prizeRank',-1,'intval');
        $bindPhone = I('get.bindPhone','');
        $export=I('get.export',0,'int');
        $where = "1";

        $luckyM = M('u_lucky_log',null,DB_MAIN_CFG);

        $startTime = strtotime($startDate);
        $endTime = strtotime($endDate);
        if($startDate && $endDate){
            $startTime = mktime(0,0,0,date("m",$startTime),date("d",$startTime),date("Y",$startTime));
            $endTime = mktime(23,59,59,date("m",$endTime),date("d",$endTime),date("Y",$endTime));
            $where .= " and addTime between $startTime and $endTime";
        } else if($startDate){
            $startTime = mktime(0,0,0,date("m",$startTime),date("d",$startTime),date("Y",$startTime));
            $where .= " and addTime >= $startTime";
        } else if($endDate){
            $endTime = mktime(23,59,59,date("m",$endTime),date("d",$endTime),date("Y",$endTime));
            $where .= " and addTime <= $endTime";
        }

        if($prizeRank < 0){
            $where .= " and prizeRank >= 0";
        } else{
            $where .= " and prizeRank = {$prizeRank}";
        }

        if($bindPhone){
            $uid = M('u_user_base',null,DB_MAIN_CFG)->where("bindPhone={$bindPhone}")->getField('uid');
            $where .= " and uid={$uid}";
        }

        $prizeLogStatusEnum = SignLuckyModel::getLuckyPrizeStatus();

        if($export){
            if($bindPhone || $startDate || $endDate || $prizeRank >= 0){
                $exportWhere = $where;
            } else{
                $exportWhere = "1 and status = 0";
            }
            $list = $luckyM
                ->field("uid,prizeRank,prizeNote,addTime")
                ->where($exportWhere)
                ->order("status ASC,prizeRank ASC,addTime DESC")
                ->select();
            $record = array();
            foreach($list as $k => $v){
                $record[$k]=array();
                $record[$k]['uid'] = $v['uid'];
                $record[$k]['prizeRank'] = $prizeLogStatusEnum[$v['prizeRank']];
                $record[$k]['prizeNote'] = strip_tags($v['prizeNote']);
                $record[$k]['addTime'] = date('Y-m-d H:i:s',$v['addTime']);
            }
            exportExcel($record, array('用户ID','抽奖结果','奖品说明','抽奖时间'),'大转盘抽奖记录_'.date('Ymd',time()));
            exit;
        } else{
            $count = $luckyM->where($where)->count();
            $this->smarty->assign('totalDataCount',$count);

            $limit = I('get.limit',10,'int');
            $Page = new Page($count,$limit);
            fetchPage($this->smarty,$Page);
            $list = $luckyM
                ->field("uid,addTime,prizeRank,prizeNote")
                ->where($where)
                ->order("status ASC,prizeRank ASC,addTime DESC")
                ->limit($Page->firstRow . ',' . $Page->listRows)
                ->select();
            if($list){
                $uidArr=array();
                foreach($list as $k => $v){
                    $list[$k]['result'] = $prizeLogStatusEnum[$v['prizeRank']];
                    $uidArr[] = $v['uid'];
                }
                $uidStr = implode(',',$uidArr);
                $info = M('u_user_base',null,DB_MAIN_CFG)->field("uid,nickname,bindPhone")->where("uid in ({$uidStr})")->select();
                foreach($list as $key => $value){
                    foreach($info as $v){
                        if($v['uid'] == $value['uid']){
                            $list[$key]['nickname'] = $v['nickname'];
                            $list[$key]['bindPhone'] = $v['bindPhone'];
                        }
                    }
                }
            }
            $this->smarty->assign('data',$list);
            $rank = array(SignLuckyModel::LUCKY_PRIZE_FIRST,SignLuckyModel::LUCKY_PRIZE_SECOND,SignLuckyModel::LUCKY_PRIZE_THIRD,
                SignLuckyModel::LUCKY_PRIZE_FORTH,SignLuckyModel::LUCKY_PRIZE_FIFTH,SignLuckyModel::LUCKY_PRIZE_NULL);
            $select = array();
            foreach($rank as $key => $res){
                $select[$key]['id'] = $res;
                $select[$key]['result'] = $prizeLogStatusEnum[$res];
            }
            $this->smarty->assign('rank',$select);
            $this->smarty->assign('prizeRank',$prizeRank);
            $this->smarty->assign('bindPhone',$bindPhone);
            $this->smarty->assign('startDate', $startDate);
            $this->smarty->assign('endDate', $endDate);
            $this->smarty->assign('limit',$limit);
            $this->smarty->assign('title',"抽奖记录");
            $this->smarty->display("Sign/luckyRecord.html");

        }
    }
    //读取卡券剩余可用数量
    public function getCardAvailableNum(){
        $cid = I('get.cid',0,'intval');
        if(!$cid){
            $this->ajaxReturn(array('status'=>1,'msg'=>'参数错误'));
        }elseif ($cid == -1){
            $this->ajaxReturn(array('status'=>0,'msg'=>0));
        }
        $count = CouponModel::getAvailableCardNum($cid);
        $this->ajaxReturn(array('status'=>0,'msg'=>$count));
    }

    //签到统计查询
    public function getSignStatistic(){
        $date = I('get.date','');
        $where = "1";
        if($date){
            $startTime = strtotime($date);
            $endTime = strtotime(date('Y-m-d 23:59:59', strtotime("$date +1 month -1 day")));
            $where .= " and objDate between {$startTime} and {$endTime}";
        }

        $count = M('u_sign_statistic',null,DB_MAIN_CFG)->where($where)->count();
        $this->smarty->assign('totalDataCount',$count);

        $limit = I('get.limit',10,'int');
        $Page = new Page($count,$limit);
        fetchPage($this->smarty,$Page);

        $data = M('u_sign_statistic',null,DB_MAIN_CFG)->where($where)->limit($Page->firstRow.','.$Page->listRows)->order("objDate DESC")->select();
        $realSignNum = array();
        foreach($data as $val){
            $realSignNum[] = $val['realSignNum'];
        }
        $totalRealNum = array_sum($realSignNum);
        $this->smarty->assign('totalRealNum',$totalRealNum);
        $this->smarty->assign('date',$date);
        $this->smarty->assign('data',$data);
        $this->smarty->assign('limit',$limit);
        $this->smarty->assign('title',"签到统计");
        $this->smarty->display("Sign/statistics.html");
    }

    //数据配置
    public function setData(){
        $sign =  M('cfg_config',null,DB_MAIN_CFG)->where("cfgName='SIGN_RANK_SET'")->find();
        if($sign){
            $data = explode(',',$sign['cfgValue']);
        } else{
            M('cfg_config',null,DB_MAIN_CFG)->add(array('cfgName'=>'SIGN_RANK_SET','cfgValue'=>'0,0,0'));
            $data = explode(',','0,0,0');
        }

        $this->smarty->assign('data',$data);
        $this->smarty->assign('title',"数据配置");
        $this->smarty->display("Sign/setData.html");
    }
    //保存签到配置
    public function saveSetData(){
        $realDayLimit = I('get.realDayLimit',-1,'intval');
        $min = I('get.min');
        $max = I('get.max');
        if(!$realDayLimit){
            $realDayLimit = -1;
        }
        $arr = array(
            0   => $realDayLimit,
            1   => $min,
            2   => $max
        );
        $data = implode(',',$arr);
        M('cfg_config',null,DB_MAIN_CFG)->where("cfgName='SIGN_RANK_SET'")->setField("cfgValue",$data);
        $this->ajaxReturn(array('status'=>0));
    }

    //抽奖次数开关控制
    public function signRewardSwitch(){
        $switch = M('cfg_config',null,DB_MAIN_CFG)->where("cfgName = 'SIGN_REWARD_SWITCH'")->getField("cfgValue");
        $switchArr = explode(',',$switch);
        $this->smarty->assign('switch',$switchArr);
        $this->smarty->display("Sign/signRewardSwitch.html");
    }

    //保存开关设置
    public function saveSwitch(){
        $fullSignSwitch = I('get.fullSignSwitch',0,'intval');
        $specialTimeSwitch = I('get.specialTimeSwitch',0,'intval');
        $rewardTimes = I('get.rewardTimes',0,'intval');
        $specialBeginDate = I('get.startDate');
        $specialEndDate = I('get.endDate');

        $specialBeginTime = strtotime($specialBeginDate);
        $specialEndTime = strtotime($specialEndDate);
        $specialEndTime = mktime(23,59,59,date('m',$specialEndTime),date('d',$specialEndTime),date('Y',$specialEndTime));

        $return = array('status'=>1,'msg'=>'请填写完整信息');

        if($specialTimeSwitch){
            if(!$rewardTimes || !$specialBeginTime || !$specialEndTime){
                $this->ajaxReturn($return);
            }
        } else{
            $rewardTimes = $specialBeginTime = $specialEndTime = 0;
        }

        $switch = $fullSignSwitch.','.$specialTimeSwitch.','.$rewardTimes.','.$specialBeginTime.','.$specialEndTime;
        if(M('cfg_config',null,DB_MAIN_CFG)->where("cfgName = 'SIGN_REWARD_SWITCH'")->find()){
            $res = M('cfg_config',null,DB_MAIN_CFG)->where("cfgName = 'SIGN_REWARD_SWITCH'")->setField("cfgValue",$switch);
            if($res !== false){
                $return['status'] = 0;
                $return['msg'] = '设置成功！';
                //写入缓存
                S('signRewardSwitch',$switch);
            } else{
                $return['msg'] = "设置失败！";
            }
            $this->ajaxReturn($return);
        } else{
            $data = array(
                'cfgName'   => 'SIGN_REWARD_SWITCH',
                'cfgValue'  => $switch,
                'desc'      => '月满签功能开关，特殊时间段奖励抽奖次数功能开关，特殊时期奖励次数，特殊时期开始时间，特殊时期结束时间'
            );
            $res=M('cfg_config',null,DB_MAIN_CFG)->add($data);
            if($res !== false){
                $return['status'] = 0;
                $return['msg'] = '设置成功！';
                //写入缓存
                S('signRewardSwitch',$switch);
            } else{
                $return['msg'] = "设置失败！";
            }
            $this->ajaxReturn($return);
        }
    }

    //大转盘功能配置
    public function signDialSet(){
        $info = M('cfg_config',null,DB_MAIN_CFG)->where("cfgName like 'SIGN_DIAL_%'")->getField('cfgName,cfgValue',true);
        $this->smarty->assign('data',$info);

        $this->smarty->display("Sign/dialSet.html");
    }
    //保存功能配置
    public function savePageSet(){
        $pageImg = I('get.pagePic');		//大转盘页面底图
        $rule = I('get.rule');				//抽奖规则
        $prizeImg = I('get.prizePic');		//奖品说明页面底图

        if(!$pageImg || !$rule || !$prizeImg){
            $this->ajaxReturn(array('status'=>1,'msg'=>'配置数据填写不完整'));
        }

        $data = array(
            array(
                'cfgName'	=> 'SIGN_DIAL_PAGE_IMG',
                'cfgValue'	=> $pageImg,
                'desc'		=> '大转盘页面底图'
            ),
            array(
                'cfgName'	=> 'SIGN_DIAL_PRIZE_IMG',
                'cfgValue'	=> $prizeImg,
                'desc'		=> '奖品说明页面底图'
            ),
            array(
                'cfgName'	=> 'SIGN_DIAL_RULE',
                'cfgValue'	=> $rule,
                'desc'		=> '积分抽奖游戏规则'
            ),
        );

        $configM = M('cfg_config',null,DB_MAIN_CFG);
        $info = $configM->where("cfgName like 'SIGN_DIAL_%'")->select();
        foreach ($info as $key => $val){
            foreach ($data as $k => $v){
                if($val['cfgName'] == $v['cfgName']){
                    if($val['cfgValue'] != $v['cfgValue']){
                        $res = $configM->where("cfgName = '{$val['cfgName']}'")->save($v);
                        if($res === false){
                            $this->ajaxReturn(array('status'=>1,'msg'=>$v['desc'].'保存失败，请重试'));
                        }
                    }
                    break;
                }
            }
        }
        $this->ajaxReturn(array('status'=>0,'msg'=>'保存成功'));
    }
}